import { default as axios } from '@/utils/request'

const prefix = '/article'

// 添加文章
// eslint-disable-next-line no-unused-vars
export function add({ title, content, desc, publish, tags, category }) {
  // FIXME:判断arguments[0]是否是对象
  const article = arguments[0]
  return axios.post(`${prefix}/add`, article)
}

// 删除文章
export function deleteArticle(id) {
  return axios.delete(`${prefix}/${id}`)
}

// 修改文章
// eslint-disable-next-line no-unused-vars
export function changeArticle(id, { title, content, desc, publish, tags, category }) {
  // FIXME:判断arguments[1]是否是对象
  const article = arguments[1]
  return axios.put(`${prefix}/${id}`, article)
}

// 设为发布
export function setPublish(id) {
  return axios.put(`${prefix}/${id}/publish`)
}

// 根据id获取文章
export function getById(id) {
  return axios.get(`${prefix}/doc/${id}`)
}

export function getHistory() {
  return axios.get(`${prefix}/history`)
}

// 获取文章发布状态
export function getPublish(uid) {
  return axios.get(`${prefix}/publish`, {
    params: {
      uid
    }
  })
}

// 获未发布的文章
export function getUnpublish() {
  return axios.get(`${prefix}/unpublish`)
}

// 获取最新文章
export function getLatest(id) {
  id = id || ""
  return axios.get(`${prefix}/latest/${id}`)
}

// 获取热门文章
export function getHot(uid) {
  return axios.get(`${prefix}/hot`, {
    params: {
      uid
    }
  })
}